package paul.idtech.lostTraveller.view;

import paul.idtech.lostTraveller.R;
import paul.idtech.lostTraveller.controller.CombatController;
import paul.idtech.lostTraveller.model.Game;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;

public class Display {

	// variables

	Bitmap backgroundBmp;

	Rect srcRect, destRect;
	
	Game game;

	public void setup(Context context, Canvas canvas, Paint paint) {

		backgroundBmp = BitmapFactory.decodeResource(context.getResources(),
				R.drawable.background_image);
		srcRect = new Rect(0, 0, backgroundBmp.getWidth(),
				backgroundBmp.getHeight());
		destRect = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());

		game = new Game(context);

	}

	public void update(Canvas canvas, Paint paint) {

		// this is where the bounce conditions for the pong ball were
		
	}

	public void draw(Canvas canvas, Paint paint) {
		//draws background
		canvas.drawBitmap(backgroundBmp, srcRect, destRect, paint);
		
		
		//draws player
		canvas.drawBitmap(game.getPlayerImage(), 200, 200, paint);
		canvas.drawText("Player Health: "+Integer.toString(game.player.getHealth()), 10, 25, paint);
		canvas.drawText("Player Energy: "+Integer.toString(game.player.getEnergy()), 10, 35, paint);
		
		//draws creature
		canvas.drawBitmap(game.getCreatureImage(), 980, 200, paint);
		canvas.drawText("Creature Health: "+Integer.toString(game.dr.creature.getHealth()), 1000, 25, paint);
		canvas.drawText("Creature Energy: "+Integer.toString(game.dr.creature.getEnergy()), 1000, 35, paint);

	}

	public boolean touchEvent(View v, MotionEvent event) {

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			float x = event.getX();
			float y = event.getY();
			if(x<=227.8 && y>=636.2){
				
				 new CombatController(game).process();
			
				
			}
			return true;
		case MotionEvent.ACTION_UP:
			// Called when user lifts finger
			return true;
		case MotionEvent.ACTION_MOVE:
			// Called every time finger coords change
			event.getX(0);
			event.getY(0);
			return true;
		default:
			return false;
		}

	}
}
